import dayjs from 'dayjs'
import store from '../store/index.js'

/**
 * @param {String} time
 * @param {String} format
 * @description 格式化时间
*/
export function dateFormat(time, format) {
	if(!time) return
	return dayjs(time).format(format || 'YYYY-MM-DD HH:mm:ss')
}

/**
 * @param {Number} type
 * @description 获取type对应label
 */
export function getTypeLabel(type) {
	const types = store.getters.types
	const currType = types.filter(item => item.value === type)
	if(currType.length) {
		return currType[0].label
	} else {
		return ''
	}
}

/**
 * @param {Number} weight
 * @description 获取weight对应label
 */
export function getWeightLabel(weight) {
	const weights = store.getters.weights
	const currWeight = weights.filter(item => item.value === weight)
	if(currWeight.length) {
		return currWeight[0].label
	} else {
		return ''
	}
}